/*
Source : https://leetcode.com/problems/reverse-linked-list/
Author : nflush@outlook.com
Date   : 2016-07-04
*/

/*
206. Reverse Linked List
Total Accepted: 121532 Total Submissions: 299649 Difficulty: Easy

Reverse a singly linked list.

click to show more hints.

Subscribe to see which companies asked this question
*/

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        ListNode *rev = head;
        ListNode *pre = NULL;
        ListNode *next = head;
        while (next){
            next = next->next;
            rev->next = pre;
            pre = rev;
            rev = next;
        }
        return pre;
    }
};

